package cnedu.ncist.authuser2.service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import edu.ncist.wang.hkdf.bussiness.blo.AbstractService;
import edu.ncist.wang.hkdf.dao.database.DBConnectionException;
import edu.ncist.wang.hkdf.dao.database.DataBaseAccess;
import edu.ncist.wang.hkdf.dao.database.DataManipulationException;

public class Authuser2Service extends AbstractService {

	public Map<String, Object> doServiceProcess(Map paraMap){
		// TODO Auto-generated method stub
		String actionType = (String)paraMap.get("ACTIONTYPE");
		if("authuser_SelectInit_New".equals(actionType)){
			return authuser_selectInit(paraMap);
		}
		else{
			ActionTypeError();
		}
		return null;
	}
	
	
	
	public Map<String, Object> authuser_selectInit(Map paraMap){
		HttpServletRequest request = (HttpServletRequest)paraMap.get("REQUEST");
		Map map = (Map)paraMap.get("CONDITIONMAP");
		Map<String, Object> resultMap = new HashMap<String, Object>();
		List<Map<String, String>> userList = null;
		DataBaseAccess dba = (DataBaseAccess)request.getAttribute("AUTHDATACONNECTION");
	   	String sql = "select topic_id,topic_name,avg(final_scorer) as pingjun FROM  "+
	   							"(SELECT * FROM(select * from job_is_hard where course_id='jsj_01' and job_id='job_01')  no1  "+
	   							"ORDER BY topic_id) average  "+
	   							"GROUP BY topic_id  "  ;
		try{
			userList = dba.getMultiRecord(sql);
			dba.close();
		}
		catch(DataManipulationException e){
			System.out.println("get user info access database error!");
			e.printStackTrace();
		}
		catch(DBConnectionException e){
			System.out.println("database close error!");
			e.printStackTrace();
		}
		if(null == userList){
			resultMap.put("RESULT", "fail");
		}
		else{
			resultMap.put("RESULT", "success");
		}
		resultMap.put("USERINFO", userList);
		resultMap.put("CONDITIONMAP", map);
		return resultMap;
	}


}
